/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package assignment2.stub;

import assignment2.data.Products;
import assignment2.data.ProductsFacade;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author tuan
 */
public class ProductsTbl_Stub {

    ProductsFacade productsFacade = lookupProductsFacadeBean();

    public void insert(Products product) {
        productsFacade.create(product);
    }

    public List<Products> listAll() {
        return productsFacade.findAll();

    }

    public Products findByID(String productID) {
        return productsFacade.find(productID);
    }

    public List<Products> listByCategoryID(String categoryID) {

        return productsFacade.searchByCategoryID(categoryID);

    }

    public void modify(Products product) {
        productsFacade.edit(product);

    }

    private ProductsFacade lookupProductsFacadeBean() {
        try {
            Context c = new InitialContext();
            return (ProductsFacade) c.lookup("java:global/Assignment2/Assignment2-ejb/ProductsFacade!assignment2.data.ProductsFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }
}
